package finance

import org.apache.commons.math.stat.inference.ChiSquareTestImpl

class ChiSquareService {
    
    static transactional = true
    def instance = new ChiSquareTestImpl()
    
    def chiSquare(expected, observed) {
        return instance.chiSquare(expected as double[], observed as long[])
    }
    
    def canBeRejected(expected, observed) {
        def rejections = []
        expected = expected as double[]
        observed = observed as long[]
        rejections << instance.chiSquareTest(expected, observed, 0.01)
        rejections << instance.chiSquareTest(expected, observed, 0.02)
        rejections << instance.chiSquareTest(expected, observed, 0.03)
        rejections << instance.chiSquareTest(expected, observed, 0.04)
        rejections << instance.chiSquareTest(expected, observed, 0.05)
        rejections << instance.chiSquareTest(expected, observed, 0.06)
        rejections << instance.chiSquareTest(expected, observed, 0.07)
        rejections << instance.chiSquareTest(expected, observed, 0.08)
        rejections << instance.chiSquareTest(expected, observed, 0.09)
        
        return rejections
    }
}
